package com.wangp.qms.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.wangp.qms.common.Constant;
import com.wangp.qms.dbcenter.DBCenter;
import com.wangp.qms.entity.User;
import com.wangp.qms.service.INumGeneratorService;

@Service("iNumGeneratorService")
public class NumGeneratorServiceImpl implements INumGeneratorService {
	
	private static final Logger log =LoggerFactory.getLogger(NumGeneratorServiceImpl.class);
	
	// VIP当前队列号码
	private Integer vipNum = 1;
	// prior当前队列号码
	private Integer priorNum = 1;
	// general当前队列号码
	private Integer generalNum = 1;

	public synchronized void generatorVipNum(User user) {
		if (user.getLevel() == Constant.CustomerType.VIP_CUSTOMER) {
			DBCenter.putVIP(vipNum, user);
			log.info("VIP客户开始排队，排队号码{}", vipNum);
			vipNum++;
		}
	}

	public synchronized void generatorPriorNum(User user) {
		if (user.getLevel() == Constant.CustomerType.PRIOR_CUSTOMER) {
			DBCenter.putPrior(priorNum, user);
			log.info("Prior客户开始排队，排队号码{}", priorNum);
			priorNum++;
		}
	}

	public synchronized void generatorGeneralNum(User user) {
		if (user.getLevel() == Constant.CustomerType.GENERAL_CUSTOMER) {
			DBCenter.putGeneral(generalNum, user);
			log.info("General客户开始排队，排队号码{}", generalNum);
			generalNum++;
		}
	}

}
